package com.lanhe.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanhe.product.domain.LhKayuProductDetails;
import com.lanhe.product.mapper.LhKayuProductContentMapper;
import com.lanhe.product.service.ILhKayuProductContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 卡鱼产品内容表(LhKayuProductContent)表服务实现类
 *
 * @author zhanggl
 * @since 2023-12-22 18:01:05
 */
@Service
public class LhKayuProductContentServiceImpl extends ServiceImpl<LhKayuProductContentMapper, LhKayuProductDetails> implements ILhKayuProductContentService {

	@Autowired
	private LhKayuProductContentMapper productContentMapper;

	/**
	 * 添加内容
	 *
	 * @param productId 产品id
	 * @param content   内容
	 * @return 结果
	 * @author zhanggl
	 * @date 2023年12月22日18:36:59
	 */
	@Override
	public int insertKayuProductContent(Long productId, String content) {

		LhKayuProductDetails productContent = new LhKayuProductDetails();
		productContent.setProductId(productId);
		productContent.setContent(content);
		return productContentMapper.insert(productContent);
	}

	/**
	 * 修改内容
	 *
	 * @param productId 产品id
	 * @param content   内容
	 * @return 结果
	 * @author zhanggl
	 * @date 2023年12月22日18:37:02
	 */
	@Override
	public int updateKayuProductContent(Long productId, String content) {
		LambdaUpdateWrapper<LhKayuProductDetails> wrapper = new LambdaUpdateWrapper<>();
		wrapper.eq(LhKayuProductDetails::getProductId, productId);
		LhKayuProductDetails productContent = new LhKayuProductDetails();
		productContent.setContent(content);
		return productContentMapper.update(productContent, wrapper);
	}

	/**
	 * 根据产品ID查询产品内容
	 *
	 * @param productId 产品ID
	 * @return com.lanhe.article.domain.LhArticleContent
	 * @author zhanggl
	 * @date 2023/12/22
	 */
	@Override
	public LhKayuProductDetails selectKayuProductContentByProductId(Long productId) {
		LambdaQueryWrapper<LhKayuProductDetails> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(LhKayuProductDetails::getProductId, productId);
		return productContentMapper.selectOne(wrapper);
	}
}

